package org.wisigoth.chat.client.jabber;

import org.wisigoth.chat.client.Message;
import org.wisigoth.chat.client.jabber.exception.UnknownPacketException;
import org.wisigoth.chat.client.msg.ChatMessage;

public class MessageFactory {

	private MessageFactory(){
		
	}
	
	public static Message createMessage(final Packet packet) throws UnknownPacketException {
		Message result = null;
		if("message".equals(packet.getElement())){
			WisigothUserImpl wisigothSender = new WisigothUserImpl(packet.getFrom());
			WisigothUserImpl wisigothReceiver = new WisigothUserImpl(packet.getTo());
			result = new ChatMessage(wisigothSender,
					wisigothReceiver, packet.getChildValue("body"));
		}
		
		if(result == null){
			throw new UnknownPacketException(packet);
		}
		return result;
		
	}
}
